from aip import AipOcr
import json
# 初始化AipOcr
APP_ID = '119699574'
API_KEY = 'cXJGbQa1PlN2nbj9vKAbh9Tu'
SECRET_KEY = 'hN4COVBR66kM9i2trQNTTfMkLYxZUrS9'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()
image = get_file_content('img.png')
# 设置可选参数
options = {
    "language_type": "CHN_ENG",
    "detect_direction": "true",
    "detect_language": "true",
    "probability": "true"
}
# 调用OCR服务
result = client.basicGeneral(image, options)
# 打印识别结果
print(json.dumps(result, indent=4, ensure_ascii=False))